﻿using PBO.Data;
using PBO.Game;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PBO.Game.BattleClass
{
    public static class PokemonHelper
    {
        public static int GetAttack(this Pokemon pm, bool ct = false)
        {
            int value = 0;
            int lv = pm.AttackLV;
            if (pm.GetSelTrait() == Trait.Simple)
                lv *= 2;
            if (pm.MyTeam.ground.Unaware && pm.GetSelTrait() != Trait.MoldBreaker)
                lv = 0;
            if (ct && lv < 0)
                lv = 0;
            value = Pokemon.CalculateAbility(pm.GetAttackValue(), lv);

            if (pm.State == PokemonState.Burn && !(pm.GetSelTrait() == Trait.Guts))
                value = Convert.ToInt32(Math.Truncate(value * 0.5));
            if (pm.GetSelTrait() == Trait.HugePower)
                value *= 2;
            if (pm.GetSelTrait() == Trait.PurePower)
                value *= 2;
            if (pm.GetSelTrait() == Trait.Guts && pm.State != PokemonState.No)
                value = Convert.ToInt32(Math.Truncate(value * 1.5));
            if (pm.GetSelTrait() == Trait.Hustle)
                value = Convert.ToInt32((Math.Truncate(value * 1.5)));
            if (pm.GetSelTrait() == Trait.SlowStart && pm.BattleState.slowStartCounter != 0)
                value = Convert.ToInt32(Math.Truncate(value * 0.5));
            if (pm.GetItem() == Item.LightBall && pm.Data.Number == 25)
                value *= 2;
            if (pm.GetItem() == Item.ThickClub && (pm.Data.Number == 105 || pm.Data.Number == 104))
                value *= 2;
            if (pm.GetItem() == Item.ChoiceBand)
                value = Convert.ToInt32(Math.Truncate(value * 1.5));
            return value;
        }

        public static bool HaveType(this Pokemon pm, BattleType type)
        {
            return pm.Type1 == type || pm.Type2 == type;
        }

        public static bool CanChange(this Pokemon pm)
        {
            return pm.MyTeam.Pokemons.Any(p => p != null && p != pm && p.HealthPower > 0 && !pm.MyTeam.SelectedPokemon.Contains(p));
        }
    }
}
